package com.easylinkin.linkappapi.camera.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.camera.entity.CameraEntity;
import com.easylinkin.linkappapi.camera.service.CameraService;
import com.easylinkin.linkappapi.common.model.RequestModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

@RestController
@RequestMapping("cameraopenApi")
@Api(tags = "摄像头接口处理")
public class CameraController {

  @Autowired
  private CameraService cameraService;

  @ApiOperation("查询摄像头的历史流水")
  @PostMapping("getHistoricDataPageFromEs")
  public RestMessage getHistoricDataPageFromEs(@RequestBody RequestModel<CameraEntity> requestModel) {
    Assert.notNull(requestModel, "参数为空");
    Assert.notNull(requestModel.getCustomQueryParams(), "参数不完整");
    IPage<Map> dataFromEs = cameraService.getHistoricDataFromEs(requestModel);
    return RestBuilders.successBuilder().data(dataFromEs).build();
  }

  @PostMapping("exportPhoto")
  @ApiOperation("抓拍相册导出")
  public RestMessage exportPhoto(@RequestBody CameraEntity dto) {
    Assert.isTrue(CollectionUtil.isNotEmpty(dto.getUrls()), "IDS不能为空");
    String fileName = cameraService.exportPhoto(dto);
    return RestBuilders.successBuilder().data(fileName).build();
  }

  @PostMapping("getCameraList")
  @ApiOperation("获取摄像头列表")
  public RestMessage getCameraList(@RequestBody CameraEntity dto) {
    List<CameraEntity> cameraEntities = cameraService.getCameraList(dto);
    return RestBuilders.successBuilder().data(cameraEntities).build();
  }
}
